#include "UGame.h"
#include "../UIniFile/UIniFile.h"
#include "UUnitOrBuildingType.h"
#include "UGameState.h"
#include "UGUI.h"
#include "UNetProt.h"

#include <boost/algorithm/string.hpp>

using namespace std;

TGame* Game;

TGame::TGame()
{	
	TIniFile* iniFile = new TIniFile();
	string s;

	ifstream UnitFile( "Data/Info/Units/Units.txt" );	// Create an input filestream
	
	// Read until the end of the file (including last line, even if it has no lineend
	for ( ; !std::getline( UnitFile, s ).eof() || !s.empty() ; s.clear())
	{
		boost::trim( s );														
		iniFile->Load("Data/Info/Units/"+s+".ini");
		UnitTypes.push_back(new TUnitType(iniFile));
	}
	UnitFile.close();


	ifstream BuildingFile( "Data/Info/Buildings/Buildings.txt" );	// Create an input filestream
	
	for ( ; !std::getline(BuildingFile, s ).eof() || !s.empty() ; s.clear())
	{
		boost::trim( s );														
		iniFile->Load("Data/Info/Buildings/"+s+".ini");
		BuildingTypes.push_back(new TBuildingType(iniFile));
	}
	BuildingFile.close();	

	gameState = TGameStateRef(new TGameState("MapA", &BuildingTypes, &UnitTypes));
	GameState = TGameStateRefConst(gameState);

	NetProt = new TNetProt(gameState);
	GUI = new TGUI(gameState);
}

void TGame::BuildBuilding(TBuildingType* type, int PosX, int PosY, float PosZ)
{
	NetProt->BuildBuilding(type, PosX, PosY, PosZ);
}


